package com.qfedu.yanglao20admin.inform.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20admin.inform.common.StateEnum;
import com.qfedu.yanglao20admin.inform.dao.AlarmRecordDao;
import com.qfedu.yanglao20admin.inform.param.AlarmRecordParam;
import com.qfedu.yanglao20admin.inform.service.AlarmRecordService;
import com.qfedu.yanglao20admin.inform.vo.AlarmRecordVO;
import com.qfedu.yanglao20admin.inform.vo.CountAlarmRecordVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yujie
 * @data 2023/4/28 10:16
 */
@Service
public class AlarmRecordServiceImpl implements AlarmRecordService {

    @Resource
    private AlarmRecordDao alarmRecordDao;


    /**
     * 分页查询告警纪录信息
     *
     * @param param 分页查询参数
     * @return 告警纪录信息
     */
    @Override
    public Page<AlarmRecordVO> pageAlarmRecord(AlarmRecordParam param) {
        // 计算偏移量
        Integer offset = (param.getPageNum() - 1) * param.getPageSize();
        param.setOffset(offset);

        // 分页查询
        Page<AlarmRecordVO> page = new Page<>(param.getPageNum(), param.getPageSize());
        List<AlarmRecordVO> alarmRecordVOS = alarmRecordDao.selectList(param);

        //  循环遍历
        for (AlarmRecordVO vo :
                alarmRecordVOS) {
            StateEnum stateById = StateEnum.getStateById(vo.getStateFlag());
            vo.setStateDesc(stateById.getDesc());
        }

        // 页码
        page.setCurrent(param.getPageNum());
        page.setSize(param.getPageSize());

        // 总记录数
        Long aLong = alarmRecordDao.selectCount(null);
        page.setTotal(aLong);

        page.setRecords(alarmRecordVOS);

        return page;
    }

    /**
     * 根据传入的时间，返回统计数量
     *
     * @param timeList 传入的时间集合
     * @return 返回统计数量
     */
    @Override
    public List<CountAlarmRecordVO> countAlarmTime(String[] timeList) {
//        String str = String.valueOf(timeList);
        List<CountAlarmRecordVO> countAlarmRecordVOS = alarmRecordDao.countAlarmTime(timeList);

        return countAlarmRecordVOS;
    }
}
